package com.moter.one.wyydemo1.controller;

import com.moter.one.wyydemo1.backstage.vo.LikeCollection;
import com.moter.one.wyydemo1.service.SongInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
//歌曲点赞和收藏量改变，1表示改变成功,0表示改变失败
public class I_D_Like_or_Collected {
   @Autowired
   SongInfoService songInfoService;
   @RequestMapping("/IDLikeOrCollected")
   public int IDLikeOrCollected(@RequestBody LikeCollection likeCollection){
      String song_id=likeCollection.getSong_id();
      String res=likeCollection.getRes();
      System.out.println("song_id = " + song_id);
      System.out.println("result = " + res);
      int f;
      if("0".equals(res)){
         //表示点赞增加
         f=songInfoService.UpdateLike(song_id,1);
         if(f>0) return 1;//修改成功
         else return 0;//修改失败
      }else if("1".equals(res)){
         //表示点赞减少
         f=songInfoService.UpdateLike(song_id,-1);
         if(f>0) return 1;//修改成功
         else return 0;//修改失败
      }else if("2".equals(res)){
         //表示收藏量增加
         f=songInfoService.UpdateCollected(song_id,1);
         if(f>0) return 1;//修改成功
         else return 0;//修改失败
      }else if("3".equals(res)){
         //表示收藏量减少
         f=songInfoService.UpdateCollected(song_id,-1);
         if(f>0) return 1;//修改成功
         else return 0;//修改失败
      }
      return 0;
   }
}
